package o;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.text.TextUtils;
import com.huawei.appmarket.framework.startevents.control.SkinResourceCache;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import o.ewm.c;
import org.json.JSONException;
import org.json.JSONObject;

public class dic {
    private static dic ˋ;

    public static class e implements flk {
        WeakReference<Context> ˏ;

        public e(Context context) {
            this.ˏ = new WeakReference(context);
        }

        public void ˏ() {
        }

        public void ॱ() {
            if (Logger.ˎ()) {
                Logger.ˏ("SkinCacheManager", "onSuccess");
            }
            Context context = (Context) this.ˏ.get();
            if (context != null) {
                Object ˏ = fmw.ˏ(context, c.ʿ, "color");
                Object ˏ2 = fmw.ˏ(context, c.ʼॱ, "color");
                if ((ˏ instanceof Integer) && (ˏ2 instanceof Integer)) {
                    evd.ˊ((Activity) context, ((Integer) ˏ).intValue(), ((Integer) ˏ2).intValue());
                }
            }
        }

        public void ˊ() {
        }
    }

    private dic() {
    }

    public static synchronized dic ˎ() {
        dic o_dic;
        synchronized (dic.class) {
            if (ˋ == null) {
                ˋ = new dic();
            }
            o_dic = ˋ;
        }
        return o_dic;
    }

    public static void ˋ(int i, int i2) {
        new eui("skin_resource" + i2).ˊ("skin_count", i);
    }

    public static int ॱ(int i) {
        return new eui("skin_resource" + i).ॱ("skin_count", 0);
    }

    public static void ˎ(SkinResourceCache skinResourceCache, int i, int i2) {
        if (skinResourceCache != null) {
            String str = null;
            try {
                str = skinResourceCache.toJson();
            } catch (IllegalAccessException e) {
                Logger.e("SkinCacheManager", "cacheStartImage error: " + e.toString());
            }
            new eui("skin_resource" + i).ˋ("skin_image_info_key" + i2, str);
        }
    }

    public static SkinResourceCache ˊ(int i, int i2) {
        Object ॱ = new eui("skin_resource" + i).ॱ("skin_image_info_key" + i2, "");
        if (TextUtils.isEmpty(ॱ)) {
            return null;
        }
        SkinResourceCache skinResourceCache = new SkinResourceCache();
        try {
            skinResourceCache.fromJson(new JSONObject(ॱ));
        } catch (IllegalAccessException e) {
            Logger.e("SkinCacheManager", "getStartImageCache error: " + e.toString());
            skinResourceCache = null;
        } catch (InstantiationException e2) {
            Logger.e("SkinCacheManager", "getStartImageCache error: " + e2.toString());
            skinResourceCache = null;
        } catch (ClassNotFoundException e3) {
            Logger.e("SkinCacheManager", "getStartImageCache error: " + e3.toString());
            skinResourceCache = null;
        } catch (JSONException e4) {
            Logger.e("SkinCacheManager", "getStartImageCache error: " + e4.toString());
            skinResourceCache = null;
        }
        return skinResourceCache;
    }

    public static void ˎ(int i) {
        new eui("skin_resource" + i).ˏˏ();
    }

    public static String ˏ(int i) {
        return ContentManager.getInstant().getFilePath() + "/SkinResource/" + String.valueOf(i) + File.separator;
    }

    public static void ˋ(int i) {
        File file = new File(ˏ(i));
        if (!file.exists() && !file.mkdirs()) {
            Logger.e("SkinCacheManager", "createSkinResourcePath failed");
        }
    }

    public static void ˋ(String str) {
        if (!TextUtils.isEmpty(str)) {
            dnw.ˊ(new File(str));
        }
    }

    public static String ˏ(SkinResourceCache skinResourceCache) {
        if (skinResourceCache == null) {
            return null;
        }
        String ॱ = skinResourceCache.ॱ();
        if (!TextUtils.isEmpty(ॱ) && new File(ॱ).exists() && ॱ.endsWith(".apk")) {
            return ॱ;
        }
        return null;
    }

    public static SkinResourceCache ˊ(int i) {
        if (dok.ᐝ(ContentManager.getInstant().getContext())) {
            return null;
        }
        int ॱ = ॱ(i);
        if (ॱ == 0) {
            return null;
        }
        for (int i2 = 0; i2 < ॱ; i2++) {
            SkinResourceCache ˊ = ˊ(i, i2);
            if (ˊ != null) {
                long ˎ = ˊ.ˎ();
                long ˊ2 = ˊ.ˊ();
                long currentTimeMillis = System.currentTimeMillis();
                if (TextUtils.isEmpty(ˊ.ॱॱ())) {
                    Logger.ˋ("SkinCacheManager", "skinPath null");
                } else if (currentTimeMillis >= ˎ && currentTimeMillis < ˊ2) {
                    return ˊ;
                } else {
                    Logger.ˋ("SkinCacheManager", "skinPath time is invaild");
                }
            }
        }
        return null;
    }

    public static String ॱ(SkinResourceCache skinResourceCache) {
        String str = null;
        if (skinResourceCache != null) {
            Object ॱॱ = skinResourceCache.ॱॱ();
            if (!TextUtils.isEmpty(ॱॱ)) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(ॱॱ).append("/particle/").append(skinResourceCache.ᐝ()).append(File.separator).append(skinResourceCache.ʽ()).append(File.separator);
                str = stringBuilder.toString();
            }
        }
        Logger.ˎ("SkinCacheManager", "path=" + str);
        return str;
    }

    public void ˎ(String str, flo o_flo, e eVar) {
        if (!TextUtils.isEmpty(str)) {
            Context ˋ = ContentManager.getInstant().getContext();
            File file = new File(str);
            if (o_flo != null) {
                flr.ˋ(ˋ).ˎ(o_flo);
            }
            boolean ˋ2 = flr.ˋ(ˋ).ˋ();
            if (Logger.ˎ()) {
                Logger.ˏ("SkinCacheManager", "hasChangeSkin:" + ˋ2);
            }
            if (ˋ2) {
                if (ॱ(str)) {
                    ˋ(flr.ˋ(ˋ).ˊ(), ˋ);
                    if (eVar != null) {
                        eVar.ॱ();
                        return;
                    }
                    return;
                }
                if (o_flo == null) {
                    o_flo = flr.ˋ(ˋ).ˋ(file.getName());
                }
                if (o_flo != null) {
                    ˋ(o_flo, ˋ);
                    flr.ˋ(ˋ).ˎ(o_flo);
                    if (eVar != null) {
                        eVar.ॱ();
                        return;
                    }
                    return;
                }
            }
            ˋ(flr.ˋ(ˋ).ˋ(file.getName()), ˋ);
            flr.ˋ(ˋ).ˎ(null);
            if (Logger.ˎ()) {
                Logger.ˏ("SkinCacheManager", "load skin");
            }
            flr.ˋ(ˋ).ˏ(str, (flk) eVar);
        }
    }

    public boolean ॱ(String str) {
        if (dnw.ˋ(str)) {
            File file = new File(str);
            flo ˊ = flr.ˋ(ContentManager.getInstant().getContext()).ˊ();
            String ˋ = ˊ == null ? null : ˊ.ˋ();
            if (dnw.ˋ(ˋ)) {
                try {
                    File file2 = new File(ˋ);
                    Object canonicalPath = file.getCanonicalPath();
                    String canonicalPath2 = file2.getCanonicalPath();
                    if (!TextUtils.isEmpty(canonicalPath) && canonicalPath.equals(canonicalPath2)) {
                        if (Logger.ˎ()) {
                            Logger.ˏ("SkinCacheManager", "isCurrentPluginPath");
                        }
                        return true;
                    }
                } catch (IOException e) {
                    Logger.e("SkinCacheManager", "getCanonicalPath exception:e" + e.toString());
                }
            }
        }
        return false;
    }

    private void ˋ(flo o_flo, Context context) {
        if (o_flo != null && context != null) {
            Resources ˎ = o_flo.ˎ();
            if (ˎ != null) {
                Configuration configuration = context.getResources().getConfiguration();
                if (ˎ.getConfiguration().getLayoutDirection() != configuration.getLayoutDirection()) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("SkinCacheManager", "checkConfigValid: config has change");
                    }
                    o_flo.ˊ(new Resources(o_flo.ˏ(), context.getResources().getDisplayMetrics(), configuration));
                }
            }
        }
    }
}
